<?php
/**
* 
*/
class Basicauth
{
	
	function __construct()
	{
			$this->CI = & get_instance();
	}
	
	function login($email, $clave){
		$data = array();
                $clave=md5($clave);
		$query = $this->CI->db->get_where('usuario', array('email' => $email, 'clave' => $clave));
		
		if($query->num_rows()>0){
			$this->CI->session->sess_destroy();
			$this->CI->session->sess_create();
			$this->CI->session->set_userdata(array('logged_in' => true, 'email' => $email, 'id' => $query->row()->idusuario));
                        $data['sessiones']=array('logged_in' => true, 'email' => $email, 'id' => $query->row()->idusuario);
		}else{
			$data['error'] = 'Usuario o contraseña incorrectos';
		}
		return $data;
		
	}
	
	function logout(){
		$this->CI->session->sess_destroy();
	}
}

?>